package com.ruoyi.project.manhua.member.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manhua.member.domain.TbMember;
import com.ruoyi.project.manhua.member.service.ITbMemberService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 会员Controller
 * 
 * @author yuan
 * @date 2021-03-03
 */
@Controller
@RequestMapping("/manhua/member")
public class TbMemberController extends BaseController
{
    private String prefix = "manhua/member";

    @Autowired
    private ITbMemberService tbMemberService;

    @RequiresPermissions("manhua:member:view")
    @GetMapping()
    public String member()
    {
        return prefix + "/member";
    }

    /**
     * 查询会员列表
     */
    @RequiresPermissions("manhua:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbMember tbMember)
    {
        startPage();
        List<TbMember> list = tbMemberService.selectTbMemberList(tbMember);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @RequiresPermissions("manhua:member:export")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbMember tbMember)
    {
        List<TbMember> list = tbMemberService.selectTbMemberList(tbMember);
        ExcelUtil<TbMember> util = new ExcelUtil<TbMember>(TbMember.class);
        return util.exportExcel(list, "member");
    }

    /**
     * 新增会员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员
     */
    @RequiresPermissions("manhua:member:add")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbMember tbMember)
    {
        return toAjax(tbMemberService.insertTbMember(tbMember));
    }

    /**
     * 修改会员
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        TbMember tbMember = tbMemberService.selectTbMemberById(userId);
        mmap.put("tbMember", tbMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员
     */
    @RequiresPermissions("manhua:member:edit")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbMember tbMember)
    {
        return toAjax(tbMemberService.updateTbMember(tbMember));
    }

    /**
     * 删除会员
     */
    @RequiresPermissions("manhua:member:remove")
    @Log(title = "会员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbMemberService.deleteTbMemberByIds(ids));
    }
}
